'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

Public Class Snac0414
    Inherits Snac

    Public Sub New()
        MyBase.New(&H4, &H14)
    End Sub

    Public Overrides Function CalculateDataSize() As Integer
        Return 8 + 2 + 1 + _ScreenName.Length + 2
    End Function

    Private _CookieID As Long
    Public Property CookieID() As Long
        Get
            Return _CookieID
        End Get
        Set(ByVal value As Long)
            _CookieID = value
        End Set
    End Property

    Private _Channel As MessageChannel
    Public Property Channel() As MessageChannel
        Get
            Return _Channel
        End Get
        Set(ByVal value As MessageChannel)
            _Channel = value
        End Set
    End Property

    Private _ScreenName As String
    Public Property ScreenName() As String
        Get
            Return _ScreenName
        End Get
        Set(ByVal value As String)
            _ScreenName = value
        End Set
    End Property


    Private _NotificationType As NotificationType
    Public Property NotificationType() As NotificationType
        Get
            Return _NotificationType
        End Get
        Set(ByVal value As NotificationType)
            _NotificationType = value
        End Set
    End Property

    Public Overrides Sub Deserialize(ByVal data As System.Collections.Generic.List(Of Byte))
        MyBase.Deserialize(data)

        Dim index As Integer = Snac.SizeFixPart

        _CookieID = CLng(ByteConverter.ToUInt64(data.GetRange(index, 8)))
        index += 8

        _Channel = DirectCast(CInt(ByteConverter.ToUInt16(data.GetRange(index, 2))), MessageChannel)
        index += 2

        _ScreenName = ByteConverter.ToStringFromByteIndex(index, data)
        index += 1 + _ScreenName.Length

        Me._NotificationType = DirectCast(CInt(ByteConverter.ToUInt16(data.GetRange(index, 2))), NotificationType)
        index += 2

        Me.SetTotalSize(index)
    End Sub

    Public Overrides Function Serialize() As System.Collections.Generic.List(Of Byte)
        Dim data As List(Of Byte) = MyBase.Serialize()

        data.AddRange(ByteConverter.GetBytes(CULng(_CookieID)))
        data.AddRange(ByteConverter.GetBytes(CUShort(_Channel)))
        data.Add(CByte(_ScreenName.Length))
        data.AddRange(ByteConverter.GetBytes(_ScreenName))

        data.AddRange(ByteConverter.GetBytes(CUShort(_NotificationType)))

        Return data
    End Function
End Class

Public Enum NotificationType
    TextCleared = &H0
    TextTyped = &H1
    TypingBegun = &H2
End Enum